/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.service.mail.WaitSetRequest.Callback;
/*     */ import com.zimbra.cs.service.mail.WaitSetRequest.TypeEnum;
/*     */ import com.zimbra.cs.session.IWaitSet;
/*     */ import com.zimbra.cs.session.WaitSetAccount;
/*     */ import com.zimbra.cs.session.WaitSetError;
/*     */ import com.zimbra.cs.session.WaitSetMgr;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestWaitSet
/*     */   extends TestCase
/*     */ {
/*     */   private static final String WS_USER_NAME = "ws_test_user";
/*     */   private static final String USER_1_NAME = "user1";
/*     */   private static final String USER_2_NAME = "user3";
/*  43 */   private static final String NAME_PREFIX = TestWaitSet.class.getSimpleName();
/*     */   private static final String FAKE_ACCOUNT_ID = "fake";
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  49 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void cleanUp() throws Exception
/*     */   {
/*  54 */     TestUtil.deleteTestData("user1", NAME_PREFIX);
/*  55 */     TestUtil.deleteTestData("user3", NAME_PREFIX);
/*     */     try {
/*  57 */       Mailbox wsMbox = TestUtil.getMailbox("ws_test_user");
/*  58 */       wsMbox.deleteMailbox();
/*     */     } catch (Exception e) {}
/*  60 */     try { TestUtil.deleteAccount("ws_test_user");
/*     */     } catch (Exception e) {}
/*     */   }
/*     */   
/*  64 */   public void testWaitSets() throws Exception { runMeFirst();
/*  65 */     runMeSecond();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private void runMeFirst()
/*     */     throws Exception
/*     */   {
/*  73 */     Account user1Acct = TestUtil.getAccount("user1");
/*  74 */     List<WaitSetAccount> add = new ArrayList();
/*  75 */     add.add(new WaitSetAccount(user1Acct.getId(), null, WaitSetRequest.TypeEnum.m.getTypes()));
/*     */     
/*  77 */     Pair<String, List<WaitSetError>> result = WaitSetMgr.create("fake", true, WaitSetRequest.TypeEnum.m.getTypes(), false, add);
/*     */     
/*  79 */     String waitSetId = (String)result.getFirst();
/*  80 */     List<WaitSetError> errors = (List)result.getSecond();
/*     */     
/*     */     try
/*     */     {
/*  84 */       String curSeqNo = "0";
/*  85 */       assertEquals(0, errors.size());
/*     */       
/*     */ 
/*  88 */       WaitSetRequest.Callback cb = new WaitSetRequest.Callback();
/*     */       
/*     */ 
/*  91 */       IWaitSet ws = WaitSetMgr.lookup(waitSetId);
/*  92 */       errors = ws.doWait(cb, "0", null, null);
/*  93 */       assertEquals(0, errors.size());
/*  94 */       synchronized (cb) { assertEquals(false, cb.completed);
/*     */       }
/*     */       
/*  97 */       String sender = TestUtil.getAddress("user1");
/*  98 */       String recipient = TestUtil.getAddress("user1");
/*  99 */       String subject = NAME_PREFIX + " testWaitSet 1";
/* 100 */       TestUtil.addMessageLmtp(subject, recipient, sender);
/* 101 */       try { Thread.sleep(500L); } catch (Exception e) {}
/* 102 */       synchronized (cb) { assertEquals(true, cb.completed); }
/* 103 */       curSeqNo = cb.seqNo;
/*     */       
/*     */ 
/*     */ 
/* 107 */       WaitSetRequest.Callback cb = new WaitSetRequest.Callback();
/*     */       
/* 109 */       IWaitSet ws = WaitSetMgr.lookup(waitSetId);
/*     */       
/*     */ 
/* 112 */       Account user2Acct = TestUtil.getAccount("user3");
/* 113 */       Object add2 = new ArrayList();
/* 114 */       ((List)add2).add(new WaitSetAccount(user2Acct.getId(), null, WaitSetRequest.TypeEnum.m.getTypes()));
/* 115 */       errors = ws.doWait(cb, curSeqNo, (List)add2, null);
/*     */       
/* 117 */       assertEquals(0, errors.size());
/* 118 */       synchronized (cb) { assertEquals(false, cb.completed);
/*     */       }
/*     */       
/* 121 */       String sender = TestUtil.getAddress("ws_test_user");
/* 122 */       String recipient = TestUtil.getAddress("user3");
/* 123 */       String subject = NAME_PREFIX + " testWaitSet 3";
/* 124 */       TestUtil.addMessageLmtp(subject, recipient, sender);
/* 125 */       try { Thread.sleep(500L); } catch (Exception e) {}
/* 126 */       synchronized (cb) { assertEquals(true, cb.completed); }
/* 127 */       curSeqNo = cb.seqNo;
/*     */     }
/*     */     finally {
/* 130 */       WaitSetMgr.destroy(null, "fake", waitSetId);
/*     */     }
/*     */   }
/*     */   
/*     */   public void runMeSecond() throws Exception {
/* 135 */     Pair<String, List<WaitSetError>> result = WaitSetMgr.create("fake", true, WaitSetRequest.TypeEnum.all.getTypes(), true, null);
/*     */     
/*     */ 
/* 138 */     String waitSetId = (String)result.getFirst();
/* 139 */     String curSeqNo = "0";
/* 140 */     List<WaitSetError> errors = (List)result.getSecond();
/* 141 */     assertEquals(0, errors.size());
/*     */     
/*     */ 
/*     */     try
/*     */     {
/* 146 */       WaitSetRequest.Callback cb = new WaitSetRequest.Callback();
/*     */       
/*     */ 
/* 149 */       IWaitSet ws = WaitSetMgr.lookup(waitSetId);
/* 150 */       errors = ws.doWait(cb, "0", null, null);
/* 151 */       assertEquals(0, errors.size());
/* 152 */       synchronized (cb) { assertEquals(false, cb.completed);
/*     */       }
/*     */       
/* 155 */       String sender = TestUtil.getAddress("user1");
/* 156 */       String recipient = TestUtil.getAddress("user1");
/* 157 */       String subject = NAME_PREFIX + " testWaitSet 1";
/* 158 */       TestUtil.addMessageLmtp(subject, recipient, sender);
/* 159 */       try { Thread.sleep(500L); } catch (Exception e) {}
/* 160 */       synchronized (cb) { assertEquals(true, cb.completed); }
/* 161 */       curSeqNo = cb.seqNo;
/*     */       
/*     */ 
/*     */ 
/* 165 */       WaitSetRequest.Callback cb = new WaitSetRequest.Callback();
/* 166 */       IWaitSet ws = WaitSetMgr.lookup(waitSetId);
/* 167 */       errors = ws.doWait(cb, "0", null, null);
/* 168 */       try { Thread.sleep(500L); } catch (Exception e) {}
/* 169 */       assertEquals(0, errors.size());
/* 170 */       synchronized (cb) { assertEquals(true, cb.completed); }
/* 171 */       curSeqNo = cb.seqNo;
/*     */       
/*     */ 
/*     */ 
/* 175 */       WaitSetRequest.Callback cb = new WaitSetRequest.Callback();
/*     */       
/* 177 */       IWaitSet ws = WaitSetMgr.lookup(waitSetId);
/* 178 */       errors = ws.doWait(cb, curSeqNo, null, null);
/* 179 */       assertEquals(0, errors.size());
/* 180 */       synchronized (cb) { assertEquals(false, cb.completed);
/*     */       }
/*     */       
/* 183 */       String subject = NAME_PREFIX + " testWaitSet document 1";
/* 184 */       TestUtil.createDocument(TestUtil.getZMailbox("user3"), "16", subject, "text/plain", "Hello, world!".getBytes());
/*     */       try {
/* 186 */         Thread.sleep(500L); } catch (Exception e) {}
/* 187 */       synchronized (cb) { assertEquals("document waitset", true, cb.completed); }
/* 188 */       curSeqNo = cb.seqNo;
/*     */       
/*     */ 
/*     */ 
/* 192 */       WaitSetRequest.Callback cb = new WaitSetRequest.Callback();
/*     */       
/*     */ 
/* 195 */       IWaitSet ws = WaitSetMgr.lookup(waitSetId);
/* 196 */       errors = ws.doWait(cb, curSeqNo, null, null);
/* 197 */       assertEquals(0, errors.size());
/* 198 */       synchronized (cb) { assertEquals(false, cb.completed);
/*     */       }
/*     */       
/* 201 */       TestUtil.createAccount("ws_test_user");
/* 202 */       synchronized (cb) { assertEquals(false, cb.completed);
/*     */       }
/*     */       
/* 205 */       String sender = TestUtil.getAddress("ws_test_user");
/* 206 */       String recipient = TestUtil.getAddress("ws_test_user");
/* 207 */       String subject = NAME_PREFIX + " testWaitSet 2";
/* 208 */       TestUtil.addMessageLmtp(subject, recipient, sender);
/* 209 */       try { Thread.sleep(500L); } catch (Exception e) {}
/* 210 */       synchronized (cb) { assertEquals(true, cb.completed); }
/* 211 */       curSeqNo = cb.seqNo;
/*     */     }
/*     */     finally {
/* 214 */       WaitSetMgr.destroy(null, "fake", waitSetId);
/*     */     }
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 220 */     cleanUp();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestWaitSet.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */